package io.dy;

import io.dy.model.WatchThreadPoolRunData;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author dmj
 */
@SpringBootApplication
public class ThreadWatchApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(ThreadWatchApplication.class, args);

//        ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
//        //获取所有线程池
//        Map<String, ThreadPoolExecutor> executors = context.getBeansOfType(ThreadPoolExecutor.class);
//
//        executor.scheduleAtFixedRate(()->{
//            List<WatchThreadPoolRunData> watchList = new ArrayList<>();
//            executors.forEach((key,value)->{
//                watchList.add(
//                        WatchThreadPoolRunData.builder()
//                            .threadPoolName(key)
//                            .corePoolSize(value.getCorePoolSize())
//                            .maximumPoolSize(value.getMaximumPoolSize())
//                            .currentPoolSize(value.getPoolSize())
//                            .activeCount(value.getActiveCount())
//                            .largestPoolSize(value.getLargestPoolSize())
//                            .completedTaskCount(value.getCompletedTaskCount())
//                            .queueSize(value.getQueue().size()).build()
//                        );
//            });
//            System.out.println(watchList);
//        },5, 5, TimeUnit.SECONDS);
    }

}
